local extension = Package:new("cptld")
extension.extensionName = "cpt_hegemony"
extension.game_modes_whitelist = {"cpt_heg_mode"}
local U = require "packages/utility/utility"
local H = require "packages/ol_hegemony/util"

Fk:loadTranslationTable{
    ["cptld"] = "竞技君临天下",
    ["cpt_ld_heg"] = "竞技君临",
  }

--阵
local dengai = General(extension, "cpt_ld_heg__dengai", "wei", 4)
dengai.mainMaxHpAdjustedValue = -1
dengai:addSkill("ld__tuntian")
dengai:addSkill("ld__jixi")
dengai:addSkill("ziliang")
Fk:loadTranslationTable{
    ["cpt_ld_heg__dengai"] = "邓艾",
    ["#cpt_ld_heg__dengai"] = "矫然的壮士",
    ["designer:cpt_ld_heg__dengai"] = "官方",
    ["illustrator:cpt_ld_heg__dengai"] = "Amo",
    ["~cpt_ld_heg__dengai"] = "君不知臣，臣不知君。罢了……罢了！",
  }

local caohong = General(extension, "cpt_ld_heg__caohong", "wei", 4)
caohong:addSkill("ldhuyuan")
caohong:addSkill("hs__heyi")
caohong:addCompanions("cpt_heg__caoren")
Fk:loadTranslationTable{
    ["cpt_ld_heg__caohong"] = "曹洪",
    ["#cpt_ld_heg__caohong"] = "魏之福将",
    ["designer:cpt_ld_heg__caohong"] = "官方",
    ["illustrator:cpt_ld_heg__caohong"] = "官方",
    ["cv:cpt_ld_heg__caohong"] = "官方",
    ["~cpt_ld_heg__caohong"] = "福兮祸所伏……",
  }

local jiangwei = General(extension, "cpt_ld_heg__jiangwei", "shu", 4)
jiangwei.deputyMaxHpAdjustedValue = -1
jiangwei:addSkill("tiaoxin")
jiangwei:addSkill("yizhi")
jiangwei:addSkill("tianfu")
jiangwei:addRelatedSkill("ld__guanxing")
jiangwei:addRelatedSkill("ld__kanpo")
jiangwei:addCompanions("cpt_heg__zhugeliang")
Fk:loadTranslationTable{
    ["cpt_ld_heg__jiangwei"] = "姜维",
    ["#cpt_ld_heg__jiangwei"] = "龙的衣钵",
    ["designer:cpt_ld_heg__jiangwei"] = "官方",
    ["~cpt_ld_heg__jiangwei"] = "臣等正欲死战，陛下何故先降……",
  }

local jiangfei = General(extension, "cpt_ld_heg__jiangwanfeiyi", "shu", 3)
jiangfei:addSkill("ld__shengxi")
jiangfei:addSkill("shoucheng")
jiangfei:addCompanions("cpt_heg__zhugeliang")
Fk:loadTranslationTable{
    ["cpt_ld_heg__jiangwanfeiyi"] = "蒋琬费祎",
    ["#cpt_ld_heg__jiangwanfeiyi"] = "社稷股肱",
    ["designer:cpt_ld_heg__jiangwanfeiyi"] = "淬毒",
    ["illustrator:cpt_ld_heg__jiangwanfeiyi"] = "cometrue",
    ["~cpt_ld_heg__jiangwanfeiyi"] = "墨守成规，终为其害啊……",
  }

local xusheng = General(extension, "cpt_ld_heg__xusheng", "wu", 4)
xusheng:addSkill("ld__yicheng")
xusheng:addCompanions("cpt_heg__dingfeng")
Fk:loadTranslationTable{
  ["cpt_ld_heg__xusheng"] = "徐盛",
  ["#cpt_ld_heg__xusheng"] = "江东的铁壁",
  ["designer:cpt_ld_heg__xusheng"] = "淬毒",
  ["illustrator:cpt_ld_heg__xusheng"] = "天信",
  ["~cpt_ld_heg__xusheng"] = "可怜一身胆略，尽随一抔黄土……",
}

local jiangqin = General(extension, "cpt_ld_heg__jiangqin", "wu", 4)
jiangqin:addSkill('ze_ld__shangyi')
jiangqin:addSkill("ze_ld_niaoxiang")
jiangqin:addCompanions("cpt_heg__zhoutai")
Fk:loadTranslationTable{
    ["cpt_ld_heg__jiangqin"] = "蒋钦",
    ["#cpt_ld_heg__jiangqin"] = "祁奚之器",
    ["designer:cpt_ld_heg__jiangqin"] = "淬毒",
    ["illustrator:cpt_ld_heg__jiangqin"] = "天空之城",
    ["cv:cpt_ld_heg__jiangqin"] = "小六",
    ["~cpt_ld_heg__jiangqin"] = "竟破我阵法...",
  }

local yuji = General(extension, "cpt_ld_heg__yuji", "qun", 3)
yuji:addSkill("qianhuan")
Fk:loadTranslationTable{
    ["cpt_ld_heg__yuji"] = "于吉",
    ["#cpt_ld_heg__yuji"] = "魂绕左右",
    ["designer:cpt_ld_heg__yuji"] = "淬毒",
    ["illustrator:cpt_ld_heg__yuji"] = "G.G.G.",
    ["~cpt_ld_heg__yuji"] = "幻化之物，终是算不得真呐。",
}
local hetaihou = General(extension, "cpt_ld_heg__hetaihou", "qun", 3, 3, General.Female)
hetaihou:addSkill("zhendu")
hetaihou:addSkill("qiluan")
Fk:loadTranslationTable{
  ["cpt_ld_heg__hetaihou"] = "何太后",
  ["#cpt_ld_heg__hetaihou"] = "弄权之蛇蝎",
  ["cv:cpt_ld_heg__hetaihou"] = "水原",
  ["illustrator:cpt_ld_heg__hetaihou"] = "KayaK&木美人",
  ["designer:cpt_ld_heg__hetaihou"] = "淬毒",
  ["~cpt_ld_heg__hetaihou"] = "你们男人造的孽，非要说什么红颜祸水……",
}

--势
local lidian = General(extension, "cpt_ld_heg__lidian", "wei", 3)
lidian:addSkill("xunxun")
lidian:addSkill("wangxi")
lidian:addCompanions("cpt_heg__yuejin")
Fk:loadTranslationTable{
  ["cpt_ld_heg__lidian"] = "李典",
  ["#cpt_ld_heg__lidian"] = "深明大义",
  ["designer:cpt_ld_heg__lidian"] = "KayaK",
  ["illustrator:cpt_ld_heg__lidian"] = "张帅",
  ["~cpt_ld_heg__lidian"] = "报国杀敌，虽死犹荣……",
}

local zangba = General(extension, "cpt_ld_heg__zangba", "wei", 4)
zangba:addSkill("ldhengjiang")
zangba:addCompanions("cpt_heg__zhangliao")
Fk:loadTranslationTable{
  ['cpt_ld_heg__zangba'] = '臧霸',
  ["#cpt_ld_heg__zangba"] = "节度青徐",
  ["illustrator:cpt_ld_heg__zangba"] = "HOOO",
  ['~cpt_ld_heg__zangba'] = '断刃沉江，负主重托……',
}

local madai = General(extension, "cpt_ld_heg__madai", "shu", 4)
madai:addSkill("heg_madai__mashu")
madai:addSkill("re__qianxi")
madai:addCompanions("cpt_heg__machao")
Fk:loadTranslationTable{
  ["cpt_ld_heg__madai"] = "马岱",
  ["#cpt_ld_heg__madai"] = "临危受命",
  ["designer:cpt_ld_heg__madai"] = "官方",
  ["illustrator:cpt_ld_heg__madai"] = "Thinking",
  ["~cpt_ld_heg__madai"] = "我怎么会死在这里……",
}

local mifuren = General(extension, "cpt_ld_heg__mifuren", "shu", 3, 3, General.Female)
mifuren:addSkill("ldguixiu")
mifuren:addSkill("cunsi")
mifuren:addRelatedSkill("yongjue")
Fk:loadTranslationTable{
    ['cpt_ld_heg__mifuren'] = '糜夫人',
    ["#cpt_ld_heg__mifuren"] = "乱世沉香",
    ["designer:cpt_ld_heg__mifuren"] = "淬毒",
    ["illustrator:cpt_ld_heg__mifuren"] = "木美人",
    ["~cpt_ld_heg__mifuren"] = "阿斗被救，妾身再无牵挂…",
  }

local sunce = General(extension, "cpt_ld_heg__sunce", "wu", 4)
sunce.deputyMaxHpAdjustedValue = -1
sunce:addCompanions { "cpt_heg__zhouyu", "cpt_heg__taishici", "cpt_heg__daqiao" }
sunce:addSkill("jiang")
sunce:addSkill("yingyang")
sunce:addSkill("hunshang")
sunce:addRelatedSkill("heg_sunce__yingzi")
sunce:addRelatedSkill("heg_sunce__yinghun")
Fk:loadTranslationTable{
    ['cpt_ld_heg__sunce'] = '孙策',
    ["#cpt_ld_heg__sunce"] = "江东的小霸王",
    ["designer:cpt_ld_heg__sunce"] = "KayaK（韩旭）",
    ["illustrator:cpt_ld_heg__sunce"] = "木美人",
    ["~cpt_ld_heg__sunce"] = "内事不决问张昭，外事不决问周瑜……",
  }

local chengdong = General(extension, "cpt_ld_heg__chenwudongxi", "wu", 4)
chengdong:addSkill("zhonger_ld_heg__duanxie")
chengdong:addSkill("zhonger_ld_heg__fenming")
Fk:loadTranslationTable{
    ['cpt_ld_heg__chenwudongxi'] = '陈武董袭',
    ["#cpt_ld_heg__chenwudongxi"] = "壮怀激烈",
    ["designer:cpt_ld_heg__chenwudongxi"] = "淬毒",
    ["illustrator:cpt_ld_heg__chenwudongxi"] = "地狱许",
    ["~cpt_ld_heg__chenwudongxi"] = "杀身卫主，死而无憾！",
  }

local dongzhuo = General(extension, "cpt_ld_heg__dongzhuo", "qun", 4)
dongzhuo:addSkill("hengzheng")
dongzhuo:addSkill("baoling")
dongzhuo:addRelatedSkill("benghuai")
Fk:loadTranslationTable{
    ['cpt_ld_heg__dongzhuo'] = '董卓',
    ["#cpt_ld_heg__dongzhuo"] = "魔王",
    ["designer:cpt_ld_heg__dongzhuo"] = "KayaK（韩旭）",
    ["illustrator:cpt_ld_heg__dongzhuo"] = "巴萨小马",
    ['~cpt_ld_heg__dongzhuo'] = '为何人人……皆与我为敌？',
}

local zhangren = General(extension, "cpt_ld_heg__zhangren", "qun", 4)
zhangren:addSkill("chuanxin")
zhangren:addSkill("fengshi")
Fk:loadTranslationTable{
  ['cpt_ld_heg__zhangren'] = '张任',
  ["#cpt_ld_heg__zhangren"] = "索命神射",
  ["designer:cpt_ld_heg__zhangren"] = "淬毒",
  ["illustrator:cpt_ld_heg__zhangren"] = "DH",
  ['~cpt_ld_heg__zhangren'] = '本将军败于诸葛，无憾……',
}

--变
local xunyou = General(extension, "cpt_ld_heg__xunyou", "wei", 3)
xunyou:addSkill("ze_ld__qice")
xunyou:addSkill("zhiyu")
xunyou:addCompanions("cpt_heg__xunyu")
Fk:loadTranslationTable{
  ["cpt_ld_heg__xunyou"] = "荀攸",
  ["#cpt_ld_heg__xunyou"] = "曹魏的谋主",
  ["designer:cpt_ld_heg__xunyou"] = "淬毒",
  ["illustrator:cpt_ld_heg__xunyou"] = "心中一凛",
  ["~cpt_ld_heg__xunyou"] = "主公，臣下……先行告退……",
}

local huaxin = General(extension, "cpt_ld_heg__huaxin", "wei", 3, 3, General.Male)
huaxin:addSkill("ty_heg__wanggui")
huaxin:addSkill("ty_heg__xibing")
Fk:loadTranslationTable{
  ["cpt_ld_heg__huaxin"] = "华歆",
  ["#cpt_ld_heg__ huaxin"] = "渊清玉洁",
  ["illustrator:cpt_ld_heg__huaxin"] = "秋呆呆",
  ["~cpt_ld_heg__huaxin"] = "大举发兵，劳民伤国。",
}


local shamoke = General(extension, "cpt_ld_heg__shamoke", "shu", 4)
shamoke:addSkill("jilis")
Fk:loadTranslationTable{
  ['cpt_ld_heg__shamoke'] = '沙摩柯',
  ["#cpt_ld_heg__shamoke"] = "五溪蛮王",
  ["illustrator:cpt_ld_heg__shamoke"] = "鬼画府",
  ["designer:cpt_ld_heg__shamoke"] = "韩旭",
  ["$jilis_cpt_ld_heg__shamoke1"] = "五溪水恶，尔等眼能全身而退。",
  ["$jilis_cpt_ld_heg__shamoke2"] = "蛮王之勇，一力当降十会。",
  ['~cpt_ld_heg__shamoke'] = "以蛮身而全汉节，虽死无憾。",
}

local masu = General(extension, "cpt_ld_heg__masu", "shu", 3)
masu:addSkill("sanyao")
masu:addSkill("ze_ld__zhiman")
Fk:loadTranslationTable{
  ['cpt_ld_heg__masu'] = '马谡',
  ["#cpt_ld_heg__masu"] = "帷幄经谋",
  ["designer:cpt_ld_heg__masu"] = "点点",
  ["illustrator:cpt_ld_heg__masu"] = "蚂蚁君",
  ["~cpt_ld_heg__masu"] = "败军之罪，万死难赎……" ,
}

local lingtong = General(extension, "cpt_ld_heg__lingtong", "wu", 4)
lingtong:addSkill("xuanlve")
lingtong:addSkill("yongjin")
lingtong:addCompanions("cpt_heg__ganning")
Fk:loadTranslationTable{
  ['cpt_ld_heg__lingtong'] = '凌统',
  ["#cpt_ld_heg__lingtong"] = "豪情烈胆",
  ["designer:cpt_ld_heg__lingtong"] = "韩旭",
  ["illustrator:cpt_ld_heg__lingtong"] = "F.源",
  ["~cpt_ld_heg__lingtong"] = "大丈夫，不惧死亡……",
}

local lvfan = General(extension, "cpt_ld_heg__lvfan", "wu", 3)
lvfan:addSkill("ld__diaodu")
lvfan:addSkill("ld__diancai")
Fk:loadTranslationTable{
  ['cpt_ld_heg__lvfan'] = '吕范',
  ["#cpt_ld_heg__lvfan"] = "忠笃亮直",
  ["designer:cpt_ld_heg__lvfan"] = "韩旭",
  ["illustrator:cpt_ld_heg__lvfan"] = "铭zmy",
  ["~cpt_ld_heg__lvfan"] = "闻主公欲授大司马之职，容臣不能……谢恩了……",
}

local zuoci = General(extension, "cpt_ld_heg__zuoci", "qun", 3)
zuoci:addSkill("gzyg")
zuoci:addSkill("gzjh")
zuoci:addCompanions("cpt_ld_heg__yuji")
Fk:loadTranslationTable{
  ["cpt_ld_heg__zuoci"] = "左慈",
  ["#cpt_ld_heg__zuoci"] = "鬼影神道",
  ["illustrator:cpt_ld_heg__zuoci"] = "吕阳",
  ["~cpt_ld_heg__zuoci"] = "红尘看破，驾鹤仙升。",
}
local lijueguosi = General(extension, "cpt_ld_heg__lijueguosi", "qun", 4)
lijueguosi:addCompanions("cpt_heg__jiaxu")
lijueguosi:addSkill("xiongsuan")
Fk:loadTranslationTable{
  ['cpt_ld_heg__lijueguosi'] = '李傕郭汜',
  ["#cpt_ld_heg__lijueguosi"] = "犯祚倾祸",
  ["designer:cpt_ld_heg__lijueguosi"] = "千幻",
  ["illustrator:cpt_ld_heg__lijueguosi"] = "旭",
  ["~cpt_ld_heg__lijueguosi"] = "异心相争，兵败战损……",
}

--权
local cuiyanmaojie = General(extension, "cpt_ld_heg__cuiyanmaojie", "wei", 3)
cuiyanmaojie:addSkill("ze_ld__zhengbi")
cuiyanmaojie:addSkill("ze_ld__fengying")
cuiyanmaojie:addCompanions("cpt_heg__caopi")
Fk:loadTranslationTable{
  ["cpt_ld_heg__cuiyanmaojie"] = "崔琰毛玠",
  ["#cpt_ld_heg__cuiyanmaojie"] = "日出月盛",
  ["designer:cpt_ld_heg__cuiyanmaojie"] = "Virgopaladin（韩旭）",
  ["illustrator:cpt_ld_heg__cuiyanmaojie"] = "兴游",
  ["~cpt_ld_heg__cuiyanmaojie"] = "为世所痛惜，冤哉……",
}


local yujin = General(extension, "cpt_ld_heg__yujin", "wei", 4)
yujin:addSkill("ld__jieyue")
yujin:addCompanions("cpt_heg__xiahoudun")
Fk:loadTranslationTable{
  ['cpt_ld_heg__yujin'] = '于禁',
  ["#cpt_ld_heg__yujin"] = "讨暴坚垒",
  ["designer:cpt_ld_heg__yujin"] = "官方",
  ["illustrator:cpt_ld_heg__yujin"] = "biou09",
  ["~cpt_ld_heg__yujin"] = "呃，晚节不保……",
}

local wangping = General(extension, "cpt_ld_heg__wangping", "shu", 4)
wangping:addCompanions("cpt_ld_heg__jiangwanfeiyi")
local jianglue = fk.CreateActiveSkill{
  name = "cpt_ld_heg__jianglue",
  frequency = Skill.Limited,
  anim_type = "support",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local index = H.startCommand(player, self.name)
    local kingdom = H.getKingdom(player)
    local targets = table.map(table.filter(room.alive_players, function(p) return H.compareKingdomWith(p, player) and p ~= player end), Util.IdMapper)
    local tos = {}
    if #targets > 0 then
      room:doIndicate(player.id, targets)
      room:sortPlayersByAction(targets)
      for _, pid in ipairs(targets) do
        local p = room:getPlayerById(pid)
        if player.dead then break end
        if not p.dead and H.doCommand(p, self.name, index, player) then
          table.insert(tos, pid)
        end
      end
    end
    table.insert(tos, 1, player.id)
    local num = 0
    for _, pid in ipairs(tos) do
      local p = room:getPlayerById(pid)
      if not p.dead then
        room:changeMaxHp(p, 1)
        if not p.dead then
          if room:recover({
            who = p,
            num = 1,
            recoverBy = player,
            skillName = self.name
          }) then
            num = num + 1
          end
        end
      end
    end
    if num > 0 then player:drawCards(num, self.name) end
  end
}
wangping:addSkill(jianglue)
Fk:loadTranslationTable{
  ["cpt_ld_heg__wangping"] = "王平",
  ["#cpt_ld_heg__wangping"] = "键闭剑门",
  ["illustrator:cpt_ld_heg__wangping"] = "zoo",
  ["cpt_ld_heg__jianglue"] = "将略",
  [":cpt_ld_heg__jianglue"] = "限定技，出牌阶段，你可选择一个“军令”，你对所有与你势力相同的角色发起此“军令”。你加1点体力上限，回复1点体力，所有执行“军令”的角色各加1点体力上限，回复1点体力。然后你摸X张牌（X为以此法回复体力的角色数）。",
  ["$cpt_ld_heg__jianglue1"] = "奇谋为短，将略为要。",
  ["$cpt_ld_heg__jianglue2"] = "为将者，需有谋略。",
  ["~cpt_ld_heg__wangping"] = "无当飞军，也有困于深林之时……",
}
local fazheng = General(extension, "cpt_ld_heg__fazheng", "shu", 3)
fazheng:addCompanions("cpt_heg__liubei")
fazheng:addSkill("ld__enyuan")
fazheng:addSkill("ze__xuanhuo")
fazheng:addRelatedSkill("xuanhur__hs__wusheng")
fazheng:addRelatedSkill("xuanhur__hs__paoxiao")
fazheng:addRelatedSkill("xuanhur__hs__longdan")
fazheng:addRelatedSkill("xuanhur__hs__tieqi")
fazheng:addRelatedSkill("xuanhur__hs__firebow")
fazheng:addRelatedSkill("xuanhur__hs__kuanggu")
Fk:loadTranslationTable{
  ["cpt_ld_heg__fazheng"] = "法正",
  ["#cpt_ld_heg__fazheng"] = "蜀汉的辅翼",
  ["illustrator:cpt_ld_heg__fazheng"] = "黑白画谱",
  ["~cpt_ld_heg__fazheng"] = "汉室复兴，我，是看不到了……",
}

local lukang = General(extension, "cpt_ld_heg__lukang", "wu", 3, 3, General.Male)
lukang:addSkill("ld__keshou")
lukang:addSkill("ld__zhuwei")
lukang:addCompanions("cpt_heg__luxun")
Fk:loadTranslationTable{
  ["cpt_ld_heg__lukang"] = "陆抗",
  ["#cpt_ld_heg__lukang"] = "孤柱扶厦",
  ["illustrator:cpt_ld_heg__lukang"] = "王立雄",
  ["~cpt_ld_heg__lukang"] = "吾既亡矣，又能存几时...",
}

local wuguotai = General(extension, "cpt_ld_heg__wuguotai", "wu", 3, 3, General.Female)
wuguotai:addSkill("ld__buyi")
wuguotai:addSkill("ganlu")
wuguotai:addCompanions("cpt_heg__sunjian")

Fk:loadTranslationTable{
  ['cpt_ld_heg__wuguotai'] = '吴国太',
  ["#cpt_ld_heg__wuguotai"] = "武烈皇后",
  ["illustrator:cpt_ld_heg__wuguotai"] = "李秀森",
  ["$ganlu_cpt_ld_heg__wuguotai1"] = "玄德实乃佳婿呀。",
  ["$ganlu_cpt_ld_heg__wuguotai2"] = "好一个郎才女貌，真是天作之合啊。",
  ["~cpt_ld_heg__wuguotai"] = "诸位卿家，还请尽力辅佐仲谋啊……",
}

local yuanshu = General(extension, "cpt_ld_heg__yuanshu", "qun", 4)
yuanshu:addCompanions("cpt_heg__jiling")
yuanshu:addSkill("zhonger_ld_heg__yongsi")
yuanshu:addSkill("ld__weidi")

Fk:loadTranslationTable{
  ['cpt_ld_heg__yuanshu'] = '袁术',
  ["#cpt_ld_heg__yuanshu"] = "仲家帝",
  ["illustrator:cpt_ld_heg__yuanshu"] = "YanBai",
  ["~cpt_ld_heg__yuanshu"] = "仲朝国祚，本应千秋万代，薪传不息……",
}

local zhangxiu = General(extension, "cpt_ld_heg__zhangxiu", "qun", 4)
zhangxiu:addSkill("ld__fudi")
zhangxiu:addSkill("ld__congjian")
zhangxiu:addCompanions("cpt_heg__jiaxu")
Fk:loadTranslationTable{
  ['cpt_ld_heg__zhangxiu'] = '张绣',
  ["#cpt_ld_heg__zhangxiu"] = "北地枪王",
  ["designer:cpt_ld_heg__zhangxiu"] = "官方",
  ["illustrator:cpt_ld_heg__zhangxiu"] = "第七个桔子",
  ["$ld__fudi_cpt_ld_heg__zhangxiu1"] = "听文和之言，得一世长久。",
  ["$ld__fudi_cpt_ld_heg__zhangxiu2"] = "谏言良策，多多益善。",
  ["$ld__congjian_cpt_ld_heg__zhangxiu1"] = "皆道明公善容人，为何营中尚有小人乎!",
  ["$ld__congjian_cpt_ld_heg__zhangxiu2"] = "吾心昭昭，愿为公清君侧、除奸臣!",
  ['~cpt_ld_heg__zhangxiu'] = '啊，这曹家，终究还是容不下我。',
}

return extension